package com.example.teesystem.common.utils;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

/**
 * @author punch
 * @data 2021-09-27 11:03
 */
public class RandomUtil {
    private final static String str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    public static String getRandomString(int length){
        StringBuilder uuid = new StringBuilder();
        for (int i = 0; i < length; i++) {
            char ch = str.charAt(new Random().nextInt(str.length()));
            uuid.append(ch);
        }
        return uuid.toString();
    }

    public static Map<Integer,Integer> getChapterIssue(int num, Integer[] chapterId){
        int count = 0;
        Map<Integer,Integer> map = new HashMap<>();
        int t = 1;
        if(num<=chapterId.length){
            for(int i = 0; i < num; i++){
                map.put(chapterId[i],1);
            }
        }else {
            while(count != num){
                for (int chapter : chapterId) {
                    map.put(chapter, t);
                    count++;
                    if(count == num) {
                        break;
                    }
                }
                t = t+1;
            }
        }
        return map;
    }
}
